var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var bodyParser = require("body-parser");
var logger = require('morgan');
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
var yichengRouter = require('./routes/yicheng');
var viewtableRouter = require('./routes/viewtable');
var editortableRouter = require('./routes/editortable');
var loginRouter = require('./routes/login');
var homeRouter = require('./routes/home');
var changepasswordRouter = require('./routes/changepassword');
var allnonjumpRouter = require('./routes/allnonjump');
var savelockRouter = require('./routes/savelock');
var analysisRouter = require('./routes/analysis');
var newAnalysisRouter = require('./routes/newAnalysis');
var SinglecellRouter = require('./routes/Singlecell');
var loadingRouter = require('./routes/loading');// 股东页面加载动画
var jilutableRouter = require('./routes/jilutable');//股东投票记录
var tongjiRouter = require('./routes/tongji');//股东投票记录
var checkpageRouter = require('./routes/checkpage');//核对数据页面
var uploadimgRouter = require('./routes/uploadimg');//上传核对数据页面的图片和信息
var app = express();
// view engine setup
app.use(bodyParser.json());
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(logger('dev'));
app.use(express.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.use(bodyParser.json({strict:false,}));

app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', indexRouter);
app.use('/viewtable', viewtableRouter);//查看表格
app.use('/editortable', editortableRouter);//编辑表格
app.use('/users', usersRouter);
app.use('/yicheng', yichengRouter);
app.use('/login', loginRouter);
app.use('/home', homeRouter);
app.use('/changepassword', changepasswordRouter);
app.use('/allnonjump', allnonjumpRouter);
app.use('/savelock', savelockRouter);
app.use('/analysis', analysisRouter);
app.use('/newAnalysis', newAnalysisRouter);
app.use('/Singlecell', SinglecellRouter);
app.use('/loading', loadingRouter);
app.use('/jilutable', jilutableRouter);
app.use('/tongji', tongjiRouter);
app.use('/checkpage', checkpageRouter);
app.use('/uploadimg', uploadimgRouter);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
  next(createError(404));
});

// error handler
app.use(function(err, req, res, next) {
  // set locals, only providing error in development
  res.locals.message = err.message;
  res.locals.error = req.app.get('env') === 'development' ? err : {};

  // render the error page
  res.status(err.status || 500);
  res.render('error');
});

module.exports = app;
